var $ = require('../../common/helper.js');
Page({
	data: {
		data: {},
		order_sn: '',
		status: '',
		name: '',
		idcard: '',
		province_name: '',
		city_name: '',
		months: [],
		total_price: 0,
		gjj_total: 0,
		service_money_total: 0,
		gjj_service_money_total: 0,
		jsApiParameters: null
	},
	onLoad: function (options) {
		this.getData(options);
	},
	getData: function (options) {
		var _this = this;
		$.get('api.php?app=member&act=order_detail&for_pay=1&id=' + options.id, function (json) {
			_this.setData({
				data: json.data,
				order_sn: json.data.order_sn,
				status: json.data.status,
				name: json.data.name,
				idcard: json.data.idcard,
				province_name: json.data.province_name,
				city_name: json.data.city_name,
				months: json.data.months,
				total_price: parseFloat(json.data.total_price),
				gjj_total: parseFloat(json.data.gjj_total),
				service_money_total: parseFloat(json.data.service_money_total),
				gjj_service_money_total: parseFloat(json.data.gjj_service_money_total),
				jsApiParameters: json.jsApiParameters
			});
		});
	},
	callApi: function (e) {
		if (this.data.data.status != 0) return;
		if (this.data.jsApiParameters) {
			var _this = this;
			$.payment(this.data.jsApiParameters, function () {
				wx.navigateTo({
					url: '/pages/cart/complete?order_sn=' + _this.data.order_sn,
				});
			});
		}
	},
	differ: function () {
		if (this.data.data.differ_money == 0) return;
		if (this.data.jsApiParameters) {
			var _this = this;
			$.payment(this.data.jsApiParameters, function () {
				$.overloadSuccess('支付差价成功');
				_this.getData({ id: _this.data.data.id });
			});
		}
	},
	refund: function () {
		var _this = this,
			data = this.data.data;
		if (data.status != 1) return;
		$.confirm({
			content: '请问您确定要申请退款吗？',
			success: function () {
				$.post('api.php?app=member&act=order_refund', { id: data.id }, function (json) {
					//$.alert('您好，我们已收到您的退款申请，请您留意“我的消息”或者“联系客服”，我们将尽快给您答复。谢谢。');
					$.alert('您好，我们已收到您的退款申请，我们将尽快为你处理。');
					_this.getData({ id: data.id });
				});
			}
		});
	},
	renew: function () {
		var data = this.data.data;
		if (data.province && data.city && data.casy_id) {
			wx.navigateTo({
				url: '/pages/cart/info?renew=1&person_id=' + data.person_id + '&province_id=' + data.province + '&city_id=' + data.city + '&casy_id=' + data.casy_id,
			});
		}
	}
})